If you've ever seen a flock of starlings flying in seemingly effortless coordination, or a school of fish avoiding some hungry sharks, you know what swarm intelligence is. The mesmerizing patterns make it appear like the flock or school is one (or several) cohesive unit(s) being guided - but it's not. The amazing thing about swarms like these is that there is no 'leader'. These patterns arise naturally as a result of a few simple rules that each swarm member follows. For example, each member in the school of fish wants to get into the center of all the other fish, to avoid the predators. In the flock of starlings, each bird has this centering tendency, but also must maintain some separation from other birds to avoid crashing. The swarm members also tend to travel in the same direction/speed as the other swarm members. For example, if they see one member turn, they'll turn too.
These are the fundamental rules that govern flocking/schooling behavior in animals. Using MATLAB, I made a simulation of this flocking behavior based on Craig Reynolds' original program, using the three aforementioned rules. In the code, each rule has a weighting term which indicates how important the rule is to the boids. By changing the weights, different types of swarms can be modeled. Fish, for example, tend to stay much closer together than birds. So the weighting factor for the cohesion rule would be greater. Insects, on the other hand, don't always tend towards a center or even in the same direction, so those weighting factors would be very low for insects . This yields much more random motion, as one might expect.
Many other modifications can be made to this simple code. For example, in this version, each boid sees every other boid. But in reality, birds and fish obstruct each other, and so the perceived size of the swarm by each member would be different depending on the location. By defining a radius around each boid that constitutes the visual range of the boid, one can more accurately model the swarming behavior. Additionally, this reduces the number of calculations drastically, and thus increases the speed and number of boids the simulation can handle. For example, my simulation can only handle about 50 to 100 boids before MATLAB runs very slowly.
Check out the video below to see what my boids look like! For more information about the actual boids programming, click here.